﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 双向绑定1改进方案
{
    public partial class Form1 : Form
    {
        private Data _data;
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }

        private void button2LoadData_Click(object sender, EventArgs e)
        {
            LoadData();
        }
        private void LoadData()
        {
            //textBox1.Text = Data.String1;
            //textBox2.Text = Data.String2;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            _data = Data.Ins;
            textBox1.DataBindings.Add("Text", _data, "String1", false, DataSourceUpdateMode.OnPropertyChanged);
            textBox2.DataBindings.Add("Text", _data, "String2", false, DataSourceUpdateMode.OnPropertyChanged);
            Task.Factory.StartNew(() =>
            {
                Thread.Sleep(3000);
                _data.String1 = $"{DateTime.Now.Second}";
                _data.String2 = $"{DateTime.Now.Millisecond}";
            });
            LoadData();
        }
        private void button1Edit_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            SaveData();
        }

        private void SaveData()
        {
            //Data.String1 = textBox1.Text;
            //Data.String2 = textBox2.Text;
        }




    }
}
